import { createRouter, createWebHashHistory } from "vue-router"
import { staticRoutes } from './staticRoutes/index'
import defaultRoutes from './defaultRoutes/index'

const routes = staticRoutes.concat(defaultRoutes)

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

//导航守卫
router.beforeEach(async(to,from,next)=>{
    let userInfo = localStorage.getItem('user')
    if (to.path === "/login") {
        next()  
    } else {
        if(userInfo) {
            next()  
        } else {
            next({path: '/login'})
        }
    }
    
})

export default router

